#include <cstdio>
#include <stack>
using namespace std;

int main()
{
	int n, p = 1;
	stack<int> st1;
	stack<int> st2;
	scanf("%d", &n);

	st1.push(n+1);
	st2.push(n+1);

	int da[n];
	for (int i = 0; i < n; i++) {
		int t;
		scanf("%d", &t);
		int s1 = st1.top();
		int s2 = st2.top();
		if (t == p) {
			p++;
			da[i]=1;
		} else
		if (t > s1 && t > s2) {
			printf("NIE\n");
			return 0;
		} else
		if (t > s1) {
			da[i] = 2;
			st2.push(t);
		} else
		if (t > s2) {
			da[i] = 1;
			st1.push(t);
		} else {
			if (s1-t < s2-t) {
				da[i] = 1;
				st1.push(t);
			} else {
				da[i] = 2;
				st2.push(t);
			}
		}
		while ((s1 == p || s2 == p) && p <= n) {
			if (s1 == p) {
				st1.pop();
				s1 = st1.top();
			}
			if (s2 == p) {
				st2.pop();
				s2 = st2.top();
			}
			p++;
		}
		if (p > n) break;
	}
	printf("TAK\n");
	for (int i = 0; i < n; i++)
		printf("%d ", da[i]);
}
